// Author: wsfuyibing <682805@qq.com>
// Date: 2025-06-16

package services

import (
	"context"
	"gitee.com/go-libs/db-xorm/db"
	"server/app/http/models"
)

// Paging
// 进货分页.
func (o *GoodsPurchaseService) Paging(ctx context.Context, data map[string]any, page, size int) (list []*models.GoodsPurchase, total int64, err error) {
	var (
		sess, s1, s2 *db.Session
	)
	if sess, err = o.Dao.Slaver(ctx); err == nil {
		s1 = sess.Where(data)
		if total, err = s1.Count(models.GoodsPurchase{}); err != nil || total == 0 {
			return
		}

		s2 = sess.Where(data)
		err = s2.OrderBy("created_at DESC").Limit(size, (page-1)*size).Find(&list)
	}
	return
}
